<template>
  <div class="header">
    <header class="public-header">
      <div class="header-top">
        <div class="public-inner">
          <a href="#" class="top-download">手机APP版下载</a>
          <a href="#" class="top-login login-signup">
            <i class="iconfont icon-tuichu"></i>注册</a>
          <a href="#" class="top-login login-signin">
            <i class="iconfont icon-denglu"></i>登录</a>
        </div>
      </div>
      <div class="public-inner">
        <!-- 米玩logo  -->
        <div class="header-logo"><img src="/public/images/logo.png" alt="米娱游戏LOGO"></div>
        <!-- 导航菜单  -->
        <nav class="header-nav">
          <ul>
            <li v-for="(item, index) in navList" :key="index" :class="{'activate-menu': item.activate}" @click="navTab(item)">
              <router-link :to="item.href">{{item.text}}</router-link>
              <span>{{item.name}}</span>
            </li>
          </ul>
        </nav>
      </div>
    </header>
  </div>
</template>

<script>
export default {
  name: 'public-header',
  data() {
    return {
      // navList: [
      //   { text: '首页', name: 'HOME', activate: this.$route.path === '/' || this.$route.path === '/about' || this.$route.path === '/consociation' ? true : false, href: '/' },
      //   { text: '游戏', name: 'GAME', activate: this.$route.path === '/game' || this.$route.path === '/details/game' ? true : false, href: '/game' },
      //   { text: '榜单', name: 'LIST', activate: this.$route.path === '/list' ? true : false, href: '/list' },
      //   { text: '礼包', name: 'GIFT', activate: this.$route.path === '/gift' || this.$route.path === '/details/gift' ? true : false, href: '/gift' },
      //   { text: '开服', name: 'PLAN', activate: this.$route.path === '/plan' ? true : false, href: '/plan' },
      //   { text: '资讯', name: 'NEWS', activate: this.$route.path === '/news' ? true : false, href: '/news' },
      //   { text: '充值', name: 'PAY', activate: this.$route.path === '/pay' ? true : false, href: '/pay' }
      // ]
    }
  },
  computed: {
    navList: function() {
      return [
        { text: '首页', name: 'HOME', activate: this.$route.path === '/' || this.$route.path === '/about' || this.$route.path === '/consociation' ? true : false, href: '/' },
        { text: '游戏', name: 'GAME', activate: this.$route.path === '/game' || this.$route.path === '/details/game' ? true : false, href: '/game' },
        { text: '榜单', name: 'LIST', activate: this.$route.path === '/list' ? true : false, href: '/list' },
        { text: '礼包', name: 'GIFT', activate: this.$route.path === '/gift' || this.$route.path === '/details/gift' ? true : false, href: '/gift' },
        { text: '开服', name: 'PLAN', activate: this.$route.path === '/plan' ? true : false, href: '/plan' },
        { text: '资讯', name: 'NEWS', activate: this.$route.path === '/news' ? true : false, href: '/news' },
        { text: '充值', name: 'PAY', activate: this.$route.path === '/pay' ? true : false, href: '/pay' }
      ]
    }
  },
  methods: {
    // 导航切换
    navTab(item) {
      this.navList.map(v => v.activate = false)
      item.activate = true
      this.$router.push(item.href)
    }
  }
}
</script>

<style lang="less" scoped>
.public-header {
  .header-top {
    background-color: #f0f0f0;
    border-bottom: 1px solid #ddd;
    height: 40px;
    line-height: 40px;
    font-size: 14px;
    margin-bottom: 24px;
    .top-download {
      float: left;
      padding-right: 34px;
      position: relative;
      color: #999;
      &:after {
        content: '';
        width: 22px;
        height: 22px;
        background: url('../assets/icon/app_icon.png') no-repeat;
        background-size: 100%;
        position: absolute;
        right: 0;
        top: 9px;
      }
      &:hover {
        text-decoration: underline;
        color: #ffa93a;
      }
    }
    .top-login {
      float: right;
      i {
        margin: 0 5px;
      }
    }
    .login-signup {
      padding-left: 20px;
      color: #999;
      &:hover {
        text-decoration: underline;
        color: #ffa93a;
      }
    }
    .login-signin {
      padding-right: 20px;
      position: relative;
      color: #999;
      &:hover {
        text-decoration: underline;
        color: #ffa93a;
      }
      &:before {
        content: '';
        width: 1px;
        height: 16px;
        background-color: #ddd;
        position: absolute;
        right: 0;
        top: 12px;
      }
    }
  }
  .header-logo {
    float: left;
  }
  .header-nav {
    float: right;
    ul {
      li {
        float: left;
        height: 55px;
        width: 100px;
        text-align: center;
        padding-top: 25px;
        position: relative;
        overflow: hidden;
        cursor: pointer;
        &:before {
          content: '';
          width: 1px;
          height: 20px;
          background-color: #ddd;
          position: absolute;
          left: 0;
          top: 25px;
          -webkit-transition: all 0.25s ease-in-out;
          transition: all 0.25s ease-in-out;
        }
        &:after {
          content: '';
          width: 0;
          height: 0;
          top: 50%;
          right: 50%;
          z-index: -1;
          position: absolute;
          -webkit-transition: all 0.25s ease-in-out;
          transition: all 0.25s ease-in-out;
        }
        &:first-child {
          &:before {
            content: '';
            width: 0;
            height: 0;
          }
        }
        a {
          color: #999;
        }
        span {
          display: none
        }


        &:hover {
          &:after {
            box-shadow: 0 0 0 100px #ffa93a;
          }
          &:before {
            height: 0;
          }
          &+li:before {
            height: 0;
          }
          a {
            color: #fff;
          }
          span {
            display: block;
            color: #fff;
          }
        }
      }
      .activate-menu {
        background-color: #ffa93a;
        &+li::before {
          height: 0;
        }
        span {
          display: block;
          color: #fff;
          cursor: pointer;
        }
        a {
          color: #fff
        }
        &:before {
          content: '';
          width: 0;
          height: 0;
          border-right: 6px solid transparent;
          border-bottom: 8px solid #fff;
          border-left: 6px solid transparent;
          background-color: transparent;
          position: absolute;
          left: 44px;
          top: 73px;
          -webkit-transition: none;
          transition: none;
        }
      }
    }
  }
}
</style>


